/*
 * @Author: [wcy]
 * @Date: 2021-12-06 13:43:58
 * @LastEditors: [wcy]
 * @LastEditTime: 2021-12-15 12:34:52
 * @Description: 
 */

import {
  showModal,showToast
} from "../../utils/asyncWx.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    address: {},
    cart: [],
    totalPrice: 0,
    totalNum: 0
  },
  onLoad() {

  },
  onShow() {
    // 获取缓存中的收货地址信息
    const address = wx.getStorageSync("address");
    // 获取缓存中的购物车数据
    let cart = wx.getStorageSync("cart") || [];
    // 过滤后的购物车数组
    cart=cart.filter(v=>v.checked)
    this.setData({address})

    let totalPrice = 0;
    let totalNum = 0;
    cart.forEach(v => {
        totalPrice += v.num * v.goods_price;
        totalNum += v.num;
    })
    this.setData({
      cart,
      totalPrice,
      totalNum,
      address
    });
  },
})